package org.tacademy.basic.calendar;

import java.util.ArrayList;

import org.tacademy.basic.calendar.CalendarManager.NoComparableObjectException;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;

import fragments.CalFragment;
import fragments.CalListFragment;

public class SampleCalenarActivity extends SherlockFragmentActivity {
    /** Called when the activity is first created. */
	private ActionBar actionBar;
	public static final int CAL = 0;
	public static final int CAL_LIST = 1;
	public static int nextPage=CAL_LIST;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    	View myButtonLayout = LayoutInflater.from(this).inflate(R.layout.mybutton,null);
		
        myButtonLayout.findViewById(R.id.mybutton1).setOnClickListener(new OnClickListener() {
  			
  			@Override
  			public void onClick(View v) {
  				// TODO Auto-generated method stub  				
  				if(nextPage == CAL) {
  					FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
	  		        CalFragment cf = new CalFragment();
	  		        
	  		        ft.replace(R.id.container, cf);
	  		        ft.commit();
	  		        nextPage = CAL_LIST;
  				} else {
  					FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
	  		        CalListFragment cf = new CalListFragment();
	  		        
	  		        ft.replace(R.id.container, cf);
	  		        ft.commit();
	  		        nextPage = CAL;
  				}
  				
  			}
  		});
        myButtonLayout.findViewById(R.id.mybutton2).setOnClickListener(new OnClickListener() {
  			
  			@Override
  			public void onClick(View v) {
  				// TODO Auto-generated method stub
  				
  			}
  		});
        
        actionBar = getSupportActionBar();
        actionBar.setCustomView(myButtonLayout);
        actionBar.setDisplayShowCustomEnabled(true);
        
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        CalFragment cf = new CalFragment();
        
        ft.add(R.id.container, cf);
        ft.commit();
        }
}